/**
 * 使用自动化工具生成 version 1.0 
 * @author Jason.Wang
 * @blog http://kany.me
 * @email kzone.wang@gmail.com
 */
package me.kany.project.spring.boot.service.impl;

import com.github.pagehelper.PageInfo;
import me.kany.project.spring.boot.mapper.BlogDocMapper;
import me.kany.project.spring.boot.model.BlogDoc;
import me.kany.project.spring.boot.service.IBlogDocService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Jason.Wang
 * @version $Id: BlogDocServiceImpl.java, v 0.1 Jason.Wang Exp $.
 */
@SuppressWarnings("serial")
@Service("blogDocService")
@Transactional
public class BlogDocServiceImpl implements IBlogDocService{
	@Autowired
	private BlogDocMapper blogDocMapper;

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#saveBlogDoc(BlogDoc)
	 */
	@Transactional(readOnly=false,rollbackFor={Exception.class})
	public int saveBlogDoc(BlogDoc blogDoc) throws Exception{
		return blogDocMapper.saveBlogDoc(blogDoc);
	}

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#saveBlogDocSelective(BlogDoc)
	 */
	@Transactional(readOnly=false,rollbackFor={Exception.class})
	public int saveBlogDocSelective(BlogDoc blogDoc) throws Exception{
		return blogDocMapper.saveBlogDocSelective(blogDoc);
	}

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#deleteBlogDocBydocId(java.lang.Integer)
	 */
	@Transactional(readOnly=false,rollbackFor={Exception.class})
	public void deleteBlogDocBydocId(java.lang.Integer docId) throws Exception{
		blogDocMapper.deleteBlogDocBydocId(docId);
	}

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#updateBlogDoc(BlogDoc)
	 */
	@Transactional(readOnly=false,rollbackFor={Exception.class})
	public int updateBlogDoc(BlogDoc blogDoc) throws Exception{
		return blogDocMapper.updateBlogDoc(blogDoc);
	}

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#queryBlogDoc(java.lang.Integer)
	 */
	@Transactional(readOnly=true,rollbackFor={Exception.class})
	public BlogDoc queryBlogDoc(java.lang.Integer docId) throws Exception{
		return blogDocMapper.queryBlogDoc(docId);
	}

	/*
	 * (non-Javadoc)
	 * @see me.kany.project.spring.boot.service.IBlogDocService#queryBlogDocList(BlogDoc)
	 */
	@Transactional(readOnly=true,rollbackFor={Exception.class})
	public List<BlogDoc> queryBlogDocList(BlogDoc blogDoc) throws Exception{
		return blogDocMapper.queryBlogDocList(blogDoc);
	}

	/**
	 * 
	 * @see me.kany.project.spring.boot.service.IBlogDocService#queryBlogDocListByPageInfo(me.kany.project.spring.boot.model.BlogDoc)
	 */
	@Transactional(readOnly=true,rollbackFor={Exception.class})
	public PageInfo<BlogDoc> queryBlogDocListByPageInfo(BlogDoc blogDoc) throws Exception {
		Map<String,Object> map =new HashMap<String,Object>();
		 map.put("blogDoc", blogDoc);
		 RowBounds rowBounds = null;
		 if(0 < blogDoc.getPage()){
		 		rowBounds = new RowBounds(blogDoc.getPage(), blogDoc.getRows());
		 }
		 PageInfo<BlogDoc> pageInfo = new PageInfo<BlogDoc>();
		 List<BlogDoc> blogDocs = blogDocMapper.queryBlogDocListByPageInfo(map,rowBounds);
		 pageInfo = new PageInfo<BlogDoc>(blogDocs);
		 return pageInfo;
	}

}